package cn.bob.org.controller;

import cn.bob.basic.query.MovleQuery;
import cn.bob.basic.utils.AjaxResult;
import cn.bob.basic.utils.PageList;
import cn.bob.org.domain.Movle;
import cn.bob.org.service.MovleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/movle")
public class MovleController {
    @Autowired
    private MovleService service;

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Movle movle){
        System.out.println(movle);
        if (movle.getMId()==null){
            service.addMovle(movle);
        }else {
            movle.setCreatetime(new Date());
            service.updateMovle(movle);
        }
        return AjaxResult.me().success();
    }
    @GetMapping
    public List<Movle> findAll(){
        return service.findMovleAll();
    }
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        service.delMovle(id);
        return AjaxResult.me().success();
    }
    @GetMapping("/{id}")
    public  Movle findById(@PathVariable("id") Long id){
        return service.findByMovleId(id);
    }
    @PostMapping
    public PageList<Movle> queryByPage(@RequestBody MovleQuery query){
        System.out.println(query);
        return service.queryByPage(query);
    }

}
